package cn.geewallet.util;

import static java.util.Objects.requireNonNull;

import java.util.List;
import java.util.regex.Pattern;


/**
 * 字符串工具类
 */
public class StringUtils {

	private static Pattern whitespacePattern = Pattern.compile("\\s");

	public static boolean containsWhitespace(String str) {
		requireNonNull(str);
		return whitespacePattern.matcher(str).find();
	}

	public static String join(String separator, List<String> input) {
		if (input == null || input.size() <= 0)
			return "";
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < input.size(); i++) {
			sb.append(input.get(i));
			// if not the last item
			if (i != input.size() - 1) {
				sb.append(separator);
			}
		}
		return sb.toString();
	}
	
	public static String joinWith(String separator, String... input) {
		if (input == null || input.length <= 0)
			return "";
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < input.length; i++) {
			sb.append(input[i]);
			// if not the last item
			if (i != input.length - 1) {
				sb.append(separator);
			}
		}
		return sb.toString();
	}

	public static String genUrl(String url, String uri) {
		if (!url.endsWith("/"))
			url += "/";
		return url += uri;
	}

	public static Boolean isEmpty(String str) {
		if (str == null)
			return true;
		return "".equals(str.trim());
	}

}
